package com.wsd.smartcarwasher.configuration;

import com.wsd.smartcarwasher.dao.SysLogMapper;
import com.wsd.smartcarwasher.domain.SysLog;
import com.wsd.smartcarwasher.service.PartnerService;
import com.wsd.smartcarwasher.util.IPUtils;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.Map;

public class GetSessionConfig {

    @Resource
    PartnerService partnerService;
    @Resource
    SysLogMapper sysLogMapper;
    public  Map<String,String>  getStorePartnerId(String operation,HttpServletRequest request)
    {
        String cellphone=request.getSession().getAttribute("cellphone").toString();
        if(cellphone==null)
        {
            return null;
        }
        Map<String,String> map=this.partnerService.getPartnerByCellphone(cellphone);
        SysLog sysLog=new SysLog();
        sysLog.setGmt_create(new Date());
        sysLog.setIp(IPUtils.getIpAddr(request));
        sysLog.setOperation(operation);
        sysLog.setType(false);
        sysLog.setUser_id("商家:"+map.get("partnerId"));
        sysLog.setUsername(map.get("name"));
        this.sysLogMapper.insert(sysLog);

        return map;
    }
}
